home *** CD-ROM | disk | FTP | other *** search
/ The Best of MacTutor - S…e Code for Volumes 1 to 5 / The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin / Source Code / #34 (Jul 88) / Window Sample Stuff / FontDialog.Asm next >
Assembly Source File  |  1987-05-06  |  43KB  |  1,205 lines

  1. ;------------------------- FontDialog ----------------------------
  2.  
  3. ; Written by Ray.A.Cameron
  4. ; Version 1
  5. ;Wed May 6, 1987 21:00:51
  6.  
  7.  
  8. XDef            FontDialog            ; Routine's name
  9.  
  10. XRef            FontMap            ; Variable's name
  11.  
  12.  
  13. ;---------- Includes -------------
  14.  
  15. Include         Traps.D            ; Use System and ToolBox traps
  16. Include         ToolEqu.D            ; Use ToolBox Equates
  17. Include            QuickEqu.D        ; Use QuickDraw Equates
  18. Include            SysEqu.D            ; Use System Equates
  19. Include            PackMacs.Txt        ; Use Package Equates
  20. Include            FontMacros.Txt    ; Use Macro file
  21.  
  22.  
  23. ; ---------- Equates ----------
  24. FontDPtr        Equ    A4
  25.  
  26. FDialog            Equ    260        ; Font dialog is DLOG resource #260
  27. ADialog        Equ    260        ; Alert dialog is ALRT resource #260
  28. True            Equ    1            ; Boolean True
  29. False            Equ    0            ; Boolean False
  30. enterCode        Equ    3            ; ASCII Enter
  31. bsCode        Equ    8            ; ASCII Back Space
  32. crCode            Equ    13            ; ASCII Carriage Return
  33. param0            Equ    0            ; Offset to string 0 in DAStrings
  34. param1            Equ    4            ; Offset to string 1 in DAStrings
  35. param2            Equ    8            ; Offset to string 2 in DAStrings
  36. OkActive        Equ    0            ; OkActive bit         within Dialog Flags
  37. SUpdate        Equ    1            ; Sample update bit    within Dialog Flags
  38. SRect            Equ    2            ; Sample rect bit     within Dialog Flags
  39. SKey            Equ    3            ; Sample key bit    within Dialog Flags
  40.  
  41. ; --------- Font Dialog Data Record -------
  42.  
  43. DStorage        Equ    $0            ; Storage for the Dialog Record
  44. TempFont        Equ    $AA        ; Currently selected font number
  45. TempFace        Equ    $AC        ; Currently selected font style
  46. TempSize        Equ    $AE        ; Currently selected font size
  47. DFlags            Equ    $B0        ; Dialog Flags
  48. NameListH        Equ    $B2        ; Font Name Selection List's Handle
  49. NameCell        Equ    $B6        ; Font Name selected cell
  50. SizeListH        Equ    $BA        ; Font Size Selection List's Handle
  51. SizeCell        Equ    $BE        ; Font Size selected cell
  52. TempCell        Equ    $C2        ; Temporary Cell variable
  53. Item            Equ    $C6        ; Item's handle or procedure
  54. Itemtype        Equ    $CA        ; Item's type
  55. ItemBox        Equ    $CC        ; Item's enclosing rect
  56. ItemHit            Equ    $D4        ; Item clicked in dialog
  57. loc_pt            Equ    $D6        ; mouse location
  58. InitBounds        Equ    $DA        ; Init size of Lists
  59. TextCursor        Equ    $E2        ; Handle to the IBeam cursor
  60. thename        Equ    $E6        ; Text string
  61. pnState        Equ    $1E6        ; Original state of the pen
  62. String1            Equ    $1F8        ; Alert text string1
  63. String2            Equ    $1FC        ; Alert text string2
  64. String3            Equ    $200        ; Alert text string3
  65. Sample            Equ    $204        ; Sample Text Edit Handle
  66. SampleRect    Equ    $208        ; Sample Text Edit Rect
  67. SampleTicks    Equ    $210        ; Ticks when Sample required updated
  68. info            Equ    $214        ; GetFontInfo record
  69. search            Equ    $21C        ; String to search Font Name List
  70.  
  71. Globalslength    Equ    $23C
  72.  
  73.  
  74. ; This routine receives the following inputs:
  75. ;     teFont: The current font's number
  76. ;    teFace: The current type face's attributes in the low byte of the word
  77. ;        Bit 0 - Bold            Bit 3 - Outline        Bit 6 - Extend
  78. ;        Bit 1 - Italic            Bit 4 - Shadow
  79. ;        Bit 2 - Underline    Bit 5 - Condense
  80. ;    teSize: The current font's size
  81. ; A ModalDialog box  is displayed to allow the user to choose the font attributes
  82. ; that they desire.  If the Ok button, enter key or carriage return is pressed
  83. ; the selected values will replace the original values otherwise the values
  84. ; remain the same.
  85.  
  86.  
  87. FontDialog
  88.  
  89.     Link            A6,#0
  90.     ; Boolean result            20(A6)        ; Ok or Cancel
  91.     ; DtxFont Address            16(A6)        ; Address of current Font number
  92.     ; DtxFace Address            12(A6)        ; Address of current Font style
  93.     ; DtxSize Address             8(A6)        ; Address of current Font size
  94.     ; Return Address             4(A6)
  95.     ; Old A6                      (A6)
  96.  
  97.     Movem.l        D0-D7/A0-A4,-(SP)        ; Save the existing register values.
  98.     Move.w        #False,20(A6)            ; Set up to return False.
  99.     
  100.     ; Create a non-relocatable block for the Font Dialog Data Record.
  101.     Move.l            #Globalslength,D0
  102.     _NewPtr        ,CLEAR
  103.     Move.l            A0,FontDRec(A5)        ; Store the pointer.
  104.     Movea.l        A0,FontDPtr
  105.  
  106.     GetPenState    pnState(A4)            ; Save the current pen settings.
  107.     ; Load the present values of the font number, face and size  
  108.     ; into temporary locations.
  109.     Movea.l        16(A6),A0                ; Font number.    
  110.     Move.w        (A0),TempFont(A4)        
  111.     Movea.l        12(A6),A0                ; Font face.    
  112.     Move.w        (A0),TempFace(A4)        
  113.     Movea.l        8(A6),A0                ; Font size.
  114.     Move.w        (A0),TempSize(A4)
  115.  
  116.     ; Obtain the iBeamCursor's resource and lock it down.
  117.     ; Function GetCursor (cursorID: Integer): CursHandle
  118.     Subq.l            #4,SP
  119.     Move.w        #iBeamCursor,-(SP)
  120.     _GetCursor
  121.     Move.l            (SP)+,TextCursor(A4)
  122.     HLock            TextCursor(A4)
  123.  
  124.     ; Function GetNewDialog (dialogID: Integer; dStorage: Ptr; 
  125.     ;                    behind: WindowPtr) : DialogPtr
  126.     Subq.l            #4,SP                    ; Space for dialog pointer.
  127.     Move.w         #FDialog,-(SP)            ; Identify dialog rsrc #.
  128.     Move.l            FontDPtr,-(SP)            ; Storage area.
  129.     Move.l            #-1,-(SP)                ; Dialog goes on top.
  130.     _GetNewDialog
  131.     _SetPort
  132.     
  133.     Move.l            OneOne,InitBounds+bottom(A4)    ; Set InitBounds to (0,0,1,1).
  134.     Bset.b            #OkActive,DFlags(A4)                ; Dialog selections are valid.
  135.     
  136.     ; Lock FontMap while its information is being accessed.
  137.     HLock            FontMap(A5)
  138.     DeRefHndle    FontMap(A5),A3        ; Dereference the FontMap handle.
  139.     
  140. ;-*- Set up the Style check boxes so that they show the current font's values.
  141.     Move.w        TempFace(A4),D0        ; Obtain the current face (style) byte.
  142.     ; Routine SControl (StItem, NofItems, ValueBits : Integer)
  143.     Move.w        #4,-(SP)                ; Item No 4.
  144.     Move.w        #5,-(SP)                ; 5 Items (check boxes).
  145.     Move.w        D0,-(SP)                ; Bits to set.
  146.     Bsr                SControl
  147.     
  148. ;-*- Set up the Spacing radio buttons so that they show the current fonts values.
  149.     Move.w        TempFace(A4),D0        ; Obtain the current face (style) byte.
  150.     Andi.w            #%01100000,D0        ; Examine Condense & Extend.
  151.     Bne.s            @0                        ; If neither of them are set, then
  152.     Move.w        #%00010000,D0        ; add a bit to represent "Normal".
  153. @0    Lsr.W            #4,D0
  154.     ; Routine SControl (StItem, NofItems, ValueBits : Integer)
  155.     Move.w        #11,-(SP)                ; Item No 11.
  156.     Move.w        #3,-(SP)                ; 3 Items (radio buttons).
  157.     Move.w        D0,-(SP)                ; Bits to set.
  158.     Bsr                SControl
  159.     
  160. ;-*- Set up the Font Name Selection Window ---------------------------------
  161.     GetDItem        FontDPtr,#17,Itemtype(A4),Item(A4),ItemBox(A4)
  162.     
  163.     ; Function LNew (rView, dataBounds: Rect; cSize: Point; theProc: Integer;
  164.     ;                    theWindow: WindowPtr; drawIt, hasGrow, scrollHoriz, 
  165.     ;                    scrollVert: Boolean): ListHandle
  166.     Subq.l            #4,SP                    ; Space for the handle.
  167.     Pea            ItemBox(A4)
  168.     Pea            InitBounds(A4)            ; Create one cell.
  169.     Clr.l            -(SP)                    ; Cell size for text.
  170.     Move.w        #0,-(SP)                ; Text definition procedure.
  171.     Move.l            FontDPtr,-(SP)
  172.     Move.b            #False,-(SP)            ; drawIt
  173.     Move.b            #False,-(SP)            ; hasGrow
  174.     Move.b            #False,-(SP)            ; scrollHoriz
  175.     Move.b            #True,-(SP)            ; scrollVert
  176.     _LNew
  177.     
  178.     Move.l            (SP),NameListH(A4)    ; Store the List's handle.
  179.     DeRefHndle    (SP)+,A0                ; Set the selection flags.
  180.     Move.b            #%10000010,selFlags(A0)      ; lOnlyOne, lNoNilHilite
  181.     Move.l            #$FFFF0000,NameCell(A4)      ; (0,-1), no cell is selected.
  182.     
  183.     Jsr                LdNames                ; Load the Font Names.
  184.  
  185. ;-*- Set up the Font Size Selection Window ---------------------------------
  186.     GetDItem        FontDPtr,#19,Itemtype(A4),Item(A4),ItemBox(A4)
  187.     
  188.     ; Function LNew (rView, dataBounds: Rect; cSize: Point; theProc: Integer;
  189.     ;                    theWindow: WindowPtr; drawIt, hasGrow, scrollHoriz, 
  190.     ;                    scrollVert: Boolean): ListHandle
  191.     Subq.l            #4,SP                    ; Space for the handle.
  192.     Pea            ItemBox(A4)
  193.     Pea            InitBounds(A4)            ; Create one cell.
  194.     Clr.l            -(SP)                    ; Cell size for text.
  195.     Move.w        #0,-(SP)                ; Text definition procedure.
  196.     Move.l            FontDPtr,-(SP)
  197.     Move.b            #False,-(SP)            ; drawIt
  198.     Move.b            #False,-(SP)            ; hasGrow
  199.     Move.b            #False,-(SP)            ; scrollHoriz
  200.     Move.b            #True,-(SP)            ; scrollVert
  201.     _LNew
  202.     
  203.     Move.l            (SP),SizeListH(A4)        ; Store the List's handle.
  204.     DeRefHndle    (SP)+,A0                ; Set the selection flags.
  205.     Move.b            #%10000010,selFlags(A0)      ; 1OnlyOne, lNoNilHilite
  206.     Move.l            #$FFFF0000,SizeCell(A4)      ; (0,-1), no cell is selected.
  207.     
  208.     Jsr                LdSizes                ; Load the current Font's Sizes.
  209.  
  210. ;-*- Set up the Font Size Text Edit item -----------------------------------
  211.     Jsr                SetEditSize
  212.     
  213. ;-*- Set up the Sample Display Text Edit Record -----------------------
  214.     GetDItem        FontDPtr,#21,Itemtype(A4),Item(A4),SampleRect(A4)
  215.     ; Function TENew (destRect, viewRect: Rect): TEHandle
  216.     Subq.l            #4,SP
  217.     Pea            SampleRect(A4)        ; Create a new text edit record.
  218.     Pea            SampleRect(A4)
  219.     _TENew
  220.     Move.l            (SP)+,Sample(A4)        ; Store theTEdit handle.
  221.     HLock            Sample(A4)
  222.     DeRefHndle    Sample(A4),A0            ; Setup the variables.
  223.     Move.w        #teJustCenter,teJust(A0)
  224.     Move.b            MinusOne,teCROnly(A0)
  225.     
  226.     GetResource    'STR ',#264                ; Obtain the sample text.
  227.     HLock            (SP)                    ; Leave the handle on the stack.
  228.     DeRefHndle    (SP),A0                ; Address of text in A0.
  229.     Clr.l            D0                        ; Length of text in D0.
  230.     Move.b            (A0)+,D0
  231.     ; Procedure TEInsert (text: Ptr; Length: LongInt; hTE: TEHandle)
  232.     Move.l            A0,-(SP)                ; Insert the sample string into
  233.     Move.l            D0,-(SP)                ; the record.
  234.     Move.l            Sample(A4),-(SP)
  235.     _TEInsert
  236.     HUnlock        (SP)+                    ; Unlock the string resource.
  237.  
  238.     Jsr                SampleWindow            ; Update the TEdit variables.
  239.     HUnlock        Sample(A4)
  240.  
  241. ;-*- Set up the Alert Dialog Variables --------------------------------------
  242.     Move.w        #-1,ACount                ; Reset the Alert stage to 1.
  243.     GetResource     'STR ',#261                ; Obtain copies of the Alert strings
  244.     Move.l            (SP)+,String1(A4)        ; handles and store them for easy
  245.     GetResource     'STR ',#262                ; access.
  246.     Move.l            (SP)+,String2(A4)
  247.     GetResource     'STR ',#263
  248.     Move.l            (SP)+,String3(A4)
  249.  
  250. ;-*-*- Display the Dialog Window -*-*---------------------------------------
  251.     ShowWindow    FontDPtr                ; This posts an Activate event.
  252.     
  253.     
  254. WaitOk    
  255.     ; Procedure ModalDialog (filterProc: ProcPtr; Var itemHit: Integer);
  256.     Pea            DUserFilter
  257.     Pea            ItemHit(A4)
  258.     _ModalDialog
  259.  
  260.     Move.w        ItemHit(A4),D0            ; Get the itemNo that was Hit.
  261.     Subq.w            #1,D0                    ; Allow for no item zero.
  262.     Lsl.w            #1,D0                    ; *2 for table index.
  263.     Move.w        ItemTable(D0),D0        ; Point to routine offset
  264.     Jmp            ItemTable(D0)            ; and jump to it.
  265.     
  266. ItemTable
  267.     Dc.w            DOk-ItemTable            ; Ok                 Button
  268.     Dc.w            DCancel-ItemTable        ; Cancel             Button
  269.     Dc.w            WaitOk-ItemTable        ; Character...         Text (Disabled)
  270.     Dc.w            SStyle-ItemTable        ; Bold                 Check Box
  271.     Dc.w            SStyle-ItemTable        ; Italic                 Check Box
  272.     Dc.w            SStyle-ItemTable        ; Underline             Check Box
  273.     Dc.w            SStyle-ItemTable        ; Outline             Check Box
  274.     Dc.w            SStyle-ItemTable        ; Shadow             Check Box
  275.     Dc.w            Style-ItemTable        ; Style                 Text (Enabled)
  276.     Dc.w            WaitOk-ItemTable        ; ThinBox             User Item (Disabled)
  277.     Dc.w            SSpacing-ItemTable    ; Normal             Radio Button
  278.     Dc.w            SSpacing-ItemTable    ; Condense         Radio Button
  279.     Dc.w            SSpacing-ItemTable    ; Extend             Radio Button
  280.     Dc.w            Spacing-ItemTable        ; Spacing             Text (Enabled)
  281.     Dc.w            WaitOk-ItemTable        ; ThinBox             User Item (Disabled)
  282.     Dc.w            WaitOk-ItemTable        ; Font N...             Text (Disabled)
  283.     Dc.w            FontName-ItemTable    ; NameSel Wind     User Item
  284.     Dc.w            WaitOk-ItemTable        ; Font S...             Text (Disabled)
  285.     Dc.w            FontSize-ItemTable    ; SizeSel Wind         User Item
  286.     Dc.w            GetEditSize-ItemTable    ; Type size            Text Edit Item
  287.     Dc.w            FontSample-ItemTable    ; Sample Font        User Item (Disabled)
  288.     
  289.     
  290. DOk
  291.     ; If the current Dialog selection isn't valid, set up the appropriate
  292.     ; param text strings and invoke the Caution Alert.
  293.     Btst.b            #OkActive,DFlags(A4)    ; Is the selection valid?
  294.     Bne            @3                        ; Yes -> @3
  295.     Clr.w            D0                        ; Set up the three param
  296.     Movea.l        #DAStrings,A0            ; text strings.
  297.     Clr.l            param0(A0)
  298.     Clr.l            param1(A0)
  299.     Clr.l            param2(A0)
  300.     Cmpi.w            #-1,TempFont(A4)        ; Is TempFont a valid selection?
  301.     Bne.s            @0                        ; Yes -> @0
  302.     Bset.b            #0,D0                    ; No -> include related text.
  303.     Move.l            String1(A4),param0(A0)
  304. @0    Cmpi.w            #0,TempSize(A4)        ; Is TempSize a valid selection?
  305.     Bne.s            @1                        ; Yes -> @1
  306.     Bset.b            #1,D0                    ; No -> include related text.
  307.     Move.l            String2(A4),param2(A0)
  308. @1    Cmpi.w            #3,D0                    ; If both TempFont and TempSize
  309.     Bne.s            @2                        ; are invalid include the conjunctive
  310.     Move.l            String3(A4),param1(A0)    ; string (String3).
  311. @2    ; Function CautionAlert (alertID: Integer; filterProc: ProcPtr): Integer
  312.     Subq.l            #2,SP
  313.     Move.w        #ADialog,-(SP)
  314.     Clr.l            -(SP)
  315.     _CautionAlert
  316.     Addq.l            #2,SP
  317.     Bra                WaitOk                    ; User to alter their selection.
  318.     
  319. @3    ; If the current Dialog selection is valid, replace the original font
  320.     ; number, style and size values with the values chosen by the user.
  321.     Movea.l        16(A6),A0                ; Font number.
  322.     Move.w        TempFont(A4),(A0)
  323.     Movea.l        12(A6),A0                ; Font style.
  324.     Move.w        TempFace(A4),(A0)
  325.     Movea.l        8(A6),A0                ; Font size.
  326.     Move.w        TempSize(A4),(A0)
  327.     Move.b            #True,20(A6)            ; Return True.
  328.     
  329. DCancel    
  330.     HideWindow    FontDPtr
  331.     LMDispose        NameListH(A4)            ; Font Name List.
  332.     LMDispose        SizeListH(A4)            ; Font Size List.
  333.     TEDispose        Sample(A4)            ; Sample Text Edit Record.
  334.     CloseDialog     FontDRec(A5)
  335.     HUnLock        FontMap(A5)            ; FontMap .
  336.     HUnLock        TextCursor(A4)            ; iBeamCursor resource.
  337.     SetPenState    pnState(A4)            ; Restore the pen settings.
  338.     DisposePtr        FontDPtr                ; Font Dialog Data Record.
  339.  
  340.     Movem.l        (SP)+,D0-D7/A0-A4    ; Restore registers.
  341.     Unlk            A6
  342.     Movea.l        (SP)+,A0                ; Pop args & return.
  343.     Add.l            #12,SP
  344.     Jmp            (A0)
  345.     
  346.     
  347. Style
  348.     Move.w        TempFace(A4),D2        ; Store for comparison later.
  349.     Movea.l        12(A6),A0                ; Obtain the original style values
  350.     Move.w        (A0),D0                ; and retain the lower five bits.
  351.     Andi.w            #%00011111,D0
  352.     Andi.w            #%11100000,TempFace(A4)    ; Clear the lower 5 bits. 
  353.     Or.w            D0,TempFace(A4)        ; Combine the two together.
  354.     Bra.s            SetStyle
  355. SStyle    
  356.     Move.w        TempFace(A4),D2        ; Store for comparison later.
  357.     Move.w        ItemHit(A4),D0            ; Get the itemNo that was hit.
  358.     Subq.w            #4,D0
  359.     Bchg.b            D0,TempFace+1(A4)    ; Toggle the selected item.
  360. SetStyle
  361.     Cmp.w            TempFace(A4),D2        ; Has the face altered?
  362.     Beq.s            @1                        ; No -> @1
  363.     Move.w        TempFace(A4),D0
  364.     ; Routine SControl (StItem, NofItems, ValueBits : Integer)
  365.     Move.w        #4,-(SP)                ; Item No 4.
  366.     Move.w        #5,-(SP)                ; 5 Items (check boxes).
  367.     Move.w        D0,-(SP)                ; Bits to set.
  368.     Bsr                SControl
  369.     Btst.b            #OkActive,DFlags(A4)    ; Are the Dialog selections valid.
  370.     Beq.s            @1                        ; No, don't update the sample.
  371.     Bclr.b            #SRect,DFlags(A4)        ; Erase the Sample Rect if it hasn't
  372.     Beq.s            @0                        ; been already.
  373.     EraseRect        SampleRect(A4)
  374. @0    Bset.b            #SUpdate,DFlags(A4)    ; Sample Window requires updating.
  375.     Move.l            Ticks,SampleTicks(A4)
  376. @1    Jmp            WaitOk
  377.  
  378.     
  379. Spacing
  380.     Move.w        TempFace(A4),D2        ; Store for comparison later.
  381.     Movea.l        12(A6),A0                ; Obtain the original style values.
  382.     Move.w        (A0),D0
  383.     Bra.s            SetSpacing
  384. SSpacing
  385.     Move.w        TempFace(A4),D2        ; Store for comparison later.
  386.     Move.w        ItemHit(A4),D1            ; Get the item No that was hit.
  387.     Sub.w            #11,D1                    ; Produce in D0 a byte that
  388.     Move.w        #%00010000,D0        ; represents which bit to set.
  389.     Lsl.b            D1,D0
  390. SetSpacing
  391.     Andi.w            #%11100000,D0        ; Clear the lower 5 bits.
  392.     Andi.w            #%00011111,TempFace(A4)    ; Clear the top 3 bits.
  393.     Or.w            D0,TempFace(A4)        ; Combine the two together.
  394.     Cmp.w            TempFace(A4),D2        ; Has the face altered?
  395.     Beq.s            @2                        ; No -> @2
  396.     Move.w        TempFace(A4),D0        ; Produce in the first 3 bits
  397.     Andi.w            #%01100000,D0        ; of D0 the settings of the
  398.     Bne.s            @0                        ; 3 radio buttons.
  399.     Move.w        #%00010000,D0
  400. @0    Lsr.b            #4,D0
  401.     ; Routine SControl (StItem, NofItems, ValueBits : Integer)
  402.     Move.w        #11,-(SP)                ; Item No 11.
  403.     Move.w        #3,-(SP)                ; 3 Items (radio buttons).
  404.     Move.w        D0,-(SP)                ; Bits to set.
  405.     Bsr                SControl
  406.     Btst.b            #OkActive,DFlags(A4)    ; Are the Dialog selections valid.
  407.     Beq.s            @2                        ; No, don't update the sample.
  408.     Bclr.b            #SRect,DFlags(A4)        ; Erase the Sample Rect if it hasn't
  409.     Beq.s            @1                        ; been already.
  410.     EraseRect        SampleRect(A4)
  411. @1    Bset.b            #SUpdate,DFlags(A4)    ; Sample Window requires updating.
  412.     Move.l            Ticks,SampleTicks(A4)
  413. @2    Jmp            WaitOk
  414.  
  415.  
  416. SControl
  417.     ; Routine SControl (StItem, NofItems, ValueBits : Integer)    
  418.     Link            A6,#0
  419.     ; StItem                    12(A6)        Start Item number
  420.     ; NofItems                    10(A6)        Number of Items
  421.     ; ValueBits                     8(A6)        Values of the items
  422.     ; Return address             4(A6)
  423.     ; Old A6                      (A6)
  424.     
  425. SetControl
  426.     GetDItem         FontDPtr,12(A6),Itemtype(A4),Item(A4),ItemBox(A4)
  427.     Clr.w            D0                        ; Set D0 to 1 if the item
  428.     Lsr.W            8(A6)                    ; is to be set or 0 if its not.
  429.     Bcc.s            @1
  430.     Addq.w            #1,D0
  431. @1    SetCtlValue     Item(A4),D0
  432.     Addq.w            #1,12(A6)                ; Increment the item No counter.
  433.     Sub.w            #1,10(A6)                ; Any more items to process?
  434.     Bne.s            SetControl                ; Yes -> SetControl.
  435.     
  436.     Unlk            A6
  437.     Movea.l        (SP)+,A0                ; Pop args & return.
  438.     Add.l            #6,SP
  439.     Jmp            (A0)
  440.     
  441.     
  442. FontName
  443.     ; The user has made a new selection from the Font Name Selection Window,
  444.     ; either a new font name or none. TempFont will change.
  445.     Bclr.b            #SRect,DFlags(A4)        ; Erase the Sample Rect if it hasn't
  446.     Beq.s            @0                        ; been already.
  447.     EraseRect        SampleRect(A4)
  448. @0    Move.w        NameCell+v(A4),D0    ; Update the font number in
  449.     Bmi.s            @1                        ; TempFont with the number
  450.     Mulu            #6,D0                    ; of the font selected .
  451.     Move.w        2(A3,D0.W),TempFont(A4)
  452.     Cmpi.w            #0,TempSize(A4)
  453.     Beq.s            @2
  454.     Bset.b            #OkActive,DFlags(A4)    ; Dialog selections are valid.
  455.     Bset.b            #SUpdate,DFlags(A4)    ; Sample Window requires updating.
  456.     Move.l            Ticks,SampleTicks(A4)
  457.     Bra.s            @3
  458. @1    Move.w        #-1,TempFont(A4)        ; No Font Name is selected.
  459. @2    Bclr.b            #OkActive,DFlags(A4)    ; Dialog selections aren't valid.
  460. @3    Jsr                LdSizes                ; Update Font Size Selection Window.
  461.     GetDItem         FontDPtr,#19,Itemtype(A4),Item(A4),ItemBox(A4)
  462.     EraseRect         ItemBox(A4)
  463.     LMUpdate         VisRgn(A4),SizeListH(A4)
  464.     Jmp            WaitOk
  465.  
  466.  
  467. FontSize
  468.     ; The user has made a new selection from the Font Size Selection Window,
  469.     ; either a new font name or none. TempSize might not change.
  470.     Move.w        TempSize(A4),D2        ; Store for comparison later.
  471.     Move.w        NameCell+v(A4),D0
  472.     Bmi.s            @0                        ; No Font Name selected.
  473.     Mulu            #6,D0
  474.     Move.w        2+4(A3,D0.W),D0        ; Offset to the font's size list.
  475.     Lea            (A3,D0.W),A0            ; Address of the size list.
  476.     Move.w        SizeCell+v(A4),D0
  477.     Bmi.s            @0                        ; No Font Size selected.
  478.     Lsl.w            #1,D0
  479.     Move.w        2(A0,D0.W),TempSize(A4)    ; Store new font size.
  480.     Cmp.w            TempSize(A4),D2        ; Has the size altered?
  481.     Beq.s            @0                        ; No -> @0
  482.     Jsr                SetEditSize            ; Update the textedit window.
  483. @0    Jmp            WaitOk
  484.     
  485.     
  486. GetEditSize
  487.     ; Convert the text in the font size text edit window into a number to update 
  488.     ; TempSize. TempSize might not have changed, if the mouse is 
  489.     ; clicked within  the font size text edit window this routine is called.
  490.     GetDItem         FontDPtr,#20,Itemtype(A4),Item(A4),ItemBox(A4)
  491.     GetIText        Item(A4),thename(A4)
  492.     Lea            thename(A4),A0
  493.     _StringToNum
  494.     Cmpi.w            #4,D0
  495.     Blt                @2                        ; if <4
  496.     Cmpi.w            #127,D0
  497.     Bgt                @2                        ; if >127
  498.     Cmp.w            TempSize(A4),D0        ; Has the size altered?
  499.     Beq.s            @1                        ; No -> @1
  500.     Move.w        D0,TempSize(A4)        ; Yes -> update TempSize.
  501.     Cmp.w            #-1,TempFont(A4)        ; Is there a valid font name?
  502.     Beq.s            @3                        ; No -> @3
  503.     Bset.b            #OkActive,DFlags(A4)    ; Dialog selections are valid.
  504.     Bclr.b            #SRect,DFlags(A4)        ; Erase the Sample Rect if it hasn't
  505.     Beq.s            @0                        ; been already.
  506.     EraseRect        SampleRect(A4)
  507. @0    Bset.b            #SUpdate,DFlags(A4)    ; Sample Window requires updating.
  508.     Move.l            Ticks,SampleTicks(A4)
  509. @1    Jmp            WaitOk
  510.  
  511. @2    Clr.w            TempSize(A4)            ; Indicate its outside limits.
  512. @3    Bclr.b            #OkActive,DFlags(A4)    ; Dialog selections aren't valid.
  513.     Bclr.b            #SRect,DFlags(A4)        ; Erase the Sample Rect if it hasn't
  514.     Beq.s            @4                        ; been already.
  515.     EraseRect        SampleRect(A4)
  516. @4    Jmp            WaitOk
  517.  
  518.  
  519. FontSample
  520.     Jsr                SampleWindow            ; update the attributes
  521.     TEUpdate        SampleRect(A4),Sample(A4)
  522.     Bclr.b            #SUpdate,DFlags(A4)    ; Sample Window has been updated.
  523.     Bset.b            #SRect,DFlags(A4)        ; Sample Rect isn't blank.
  524.     Jmp            WaitOk
  525.  
  526.  
  527. SetEditSize
  528.     ; Setup the font size text edit item. To access this routine there must be a valid
  529.     ; font name.
  530.     GetDItem         FontDPtr,#20,Itemtype(A4),Item(A4),ItemBox(A4)
  531.     Clr.l            D7
  532.     Move.w        TempSize(A4),D7        
  533.     Cmpi.w            #4,D7
  534.     Blt                @1                        ; if <4
  535.     Cmpi.w            #127,D7
  536.     Bgt                @1                        ; if >127
  537.     Bset.b            #OkActive,DFlags(A4)    ; Dialog selections are valid.
  538.     Bclr.b            #SRect,DFlags(A4)        ; Erase the Sample Rect if it hasn't
  539.     Beq.s            @0                        ; been already.
  540.     EraseRect        SampleRect(A4)
  541. @0    Bset.b            #SUpdate,DFlags(A4)    ; Sample Window requires updating.
  542.     Move.l            Ticks,SampleTicks(A4)
  543.     Lea            thename(A4),A0        ; Load thename pointer.
  544.     Move.l            D7,D0
  545.     _NumToString
  546.     Move.l            Item(A4),-(SP)            ; Set the item text to the new
  547.     Move.l            A0,-(SP)                ; number string.
  548.     _SetIText
  549.     ; Procedure SelIText (theDialog: DialogPtr; itemNo: Integer;
  550.     ;                    strtSel,endSel: Integer);
  551.     Move.l            FontDPtr,-(SP)
  552.     Move.w        #20,-(SP)                ; Select the complete text in the item.
  553.     Move.w        #0,-(SP)
  554.     Move.w        #255,-(SP)
  555.     _SelIText
  556.     Rts
  557.  
  558. @1    Clr.w            TempSize(A4)            ; Indicate it's outside limits.
  559.     Bclr.b            #OkActive,DFlags(A4)    ; Dialog selections aren't valid.
  560.     Bclr.b            #SRect,DFlags(A4)        ; Erase the Sample Rect if it hasn't
  561.     Beq.s            @2                        ; been already.
  562.     EraseRect        SampleRect(A4)
  563. @2    Rts
  564.  
  565.     
  566. LdNames
  567.     ; Load the NameList  with the font names stored in FontMap.
  568.     ; Function LAddRow (count, rowNum: Integer; lHandle: ListHandle): Integer
  569.     Subq.l            #2,SP
  570.     Move.w        (A3),-(SP)                ; The number of font names - 1.
  571.     Move.w        #0,-(SP)
  572.     Move.l            NameListH(A4),-(SP)
  573.     _LAddRow
  574.     Addq.l            #2,SP
  575.     
  576.     Clr.w            D7                        ; Loop counter (the # of fonts -1).
  577. @0    Move.w        D7,D6
  578.     Mulu            #6,D6                    ; Point to the next font info.
  579.     Move.w        2(A3,D6.W),D0            ; Obtain the font's number.
  580.     Cmp.w            TempFont(A4),D0        ; Is this the font to be selected?
  581.     Bne.s            @1                        ; No -> @1.
  582.     Move.w        D7,NameCell+v(A4)    ; Store the cell # into NameCell+v.
  583. @1    Move.w        2+2(A3,D6.W),D6        ; Obtain the font's name offset.
  584.  
  585.     ; Procedure LSetCell (dataPtr: Ptr; dataLen: Integer; theCell: Cell;
  586.     ;                    lHandle: ListHandle)
  587.     Pea            1(A3,D6.W)            ; Address of the name (string).
  588.     Clr.w            D0
  589.     Move.b            (A3,D6.W),D0            ; Length of the name.
  590.     Move.w        D0,-(SP)    
  591.     Move.w        #0,-(SP)                ; Cell column #.
  592.     Move.w        D7,-(SP)                ; Cell row #.
  593.     Move.l            NameListH(A4),-(SP)
  594.     _LSetCell
  595.     
  596.     Addq.w            #1,D7                    ; Increment the loop counter.
  597.     Cmp.w            (A3),D7                ; Loaded all font names yet?
  598.     Ble.s            @0                        ; No -> @0.
  599.     
  600. ; Select the cell containing the font name which corresponds to the font number passed to the
  601. ; FontDialog Routine.  If the font number isn't associated with one of the fonts on the 
  602. ; current system file then don't select any name.
  603.     Cmpi.w            #-1,NameCell+v(A4)    ; Cell to be selected?
  604.     Beq.s            @2                        ; No -> @2
  605.     LMSetSelect     #True,NameCell(A4),NameListH(A4)
  606.     
  607.     DeRefHndle    NameListH(A4),A0        ; Scroll if the selected cell isn't
  608.     Move.w        visible+bottom(A0),D6    ; visible, ie the last visible cell is
  609.     Cmp.w            NameCell+v(A4),D6    ; less than the selected cell.
  610.     Bgt.s            @2
  611.     LMAutoScroll    NameListH(A4)
  612.     
  613. @2    LMDoDraw         #True,NameListH(A4)    ; Drawing on.
  614.     Rts
  615.  
  616.     
  617. LdSizes
  618.     ; load the SizeList with the font sizes of TempFont stored in FontMap.
  619.     LMDoDraw         #False,SizeListH(A4)    ; Drawing off.
  620.     LMDelRow         #0,#0,SizeListH(A4)    ; Delete all the rows.
  621.     Move.l            #$FFFF0000,SizeCell(A4)
  622.     Move.w        TempFont(A4),D4        ;The font number.
  623.     Bmi            @5                        ; -ve, no font number was passed to FontDialog.
  624.     
  625.     Clr.w            D7                        ; Loop counter.
  626. @1    Move.w        D7,D6
  627.     Mulu            #6,D6                    ; Point to the next font info.
  628. ; Compare the font number with the font number that was passed to the FontDialog Routine.
  629.     Cmp.w            2(A3,D6.W),D4            ; Match?
  630.     Beq.s            @2                        ; Yes -> @2.
  631.     Addq.w            #1,D7                    ; Increment the loop counter.
  632.     Cmp.w            (A3),D7                ; Looked at all the font numbers yet?
  633.     Ble.s            @1                        ; No ->@1.
  634.     Bra                @5                        ; Yes & no match was found.
  635.     
  636. @2    Move.w        2+4(A3,D6.W),D7        ; Offset to the font size list.
  637.     Move.w        (A3,D7.W),D6            ; The number of font sizes.
  638.     ; Procedure LAddRow (count, rowNum: Integer; lHandle: ListHandle): Integer
  639.     Subq.l            #2,SP
  640.     Move.w        D6,-(SP)                ; Number of rows to add.
  641.     Move.w        #0,-(SP)
  642.     Move.l            SizeListH(A4),-(SP)
  643.     _LAddRow
  644.     Addq.l            #2,SP
  645.     
  646.     Clr.w            D6                        ; Setup the loop counter.
  647. @3    Move.w        D6,D5                    ; Create an offset within the size list.
  648.     Lsl.w            #1,D5
  649.     Add.w            D7,D5                    ; Offset from the start of FontMap.
  650.     Clr.l            D0                        ; Clear .L for NumToString.
  651.     Move.w        2(A3,D5.W),D0            ; A font size.
  652.     Cmp.w            TempSize(A4),D0        ; Is this the selected size?
  653.     Bne.s            @4                        ; No -> @4.
  654.     Move.w        D6,SizeCell+v(A4)        ; Store the cell number to be selected.
  655. @4    Lea            thename(A4),A0
  656.     _NumToString
  657.     ; Procedure LSetCell (dataPtr: Ptr; dataLen: Integer; theCell: Cell;
  658.     ;                    lHandle: ListHandle)
  659.     Pea            1(A0)                    ; Address of the Size (string).
  660.     Clr.w            D0
  661.     Move.b            (A0),D0                ; Length of the Size.
  662.     Move.w        D0,-(SP)
  663.     Move.w        #0,-(SP)                ; Cell column #.
  664.     Move.w        D6,-(SP)                ; Cell row #.
  665.     Move.l            SizeListH(A4),-(SP)
  666.     _LSetCell
  667.     
  668.     Addq.w            #1,D6                    ; Increment the loop counter.
  669.     Cmp.w            (A3,D7.W),D6            ; Loaded all font sizes yet?
  670.     Blt.s            @3                        ; No -> @3.
  671.     
  672. ; Select the cell containing the font size which corresponds to the font size passed to the
  673. ; FontDialog Routine.  If the font doesn't have the size selected, do nothing.
  674.     Cmpi.w            #-1,SizeCell+v(A4)        ; Cell to be selected?
  675.     Beq.s            @5                        ; No -> @5
  676.     LMSetSelect     #True,SizeCell(A4),SizeListH(A4)
  677.     
  678.     DeRefHndle    SizeListH(A4),A0        ; Scroll if the selected cell isn't
  679.     Move.l            (A0),A0                ; visible, ie the last visible cell is
  680.     Move.w        visible+bottom(A0),D6    ; less than the selected cell.
  681.     Cmp.w            SizeCell+v(A4),D6
  682.     Bgt.s            @5
  683.     LMAutoScroll    SizeListH(A4)
  684.     
  685. @5    LMDoDraw         #True,SizeListH(A4)    ; Drawing on.
  686.     Rts
  687.  
  688.  
  689. SampleWindow
  690.     ; Update the sample TextEdit Record with the currently
  691.     ; selected font attributes.
  692.     Btst.b            #OkActive,DFlags(A4)    ; Are the selections valid?
  693.     Beq            @0                        ; No -> @0
  694.     TextFont        TempFont(A4)            ; Font number
  695.     TextFace        TempFace(A4)            ; Font style
  696.     TextSize        TempSize(A4)            ; Font size
  697.     GetFontInfo    info(A4)
  698.     
  699.     DeRefHndle    Sample(A4),A0
  700.     Move.w        TempFont(A4),teFont(A0)        ; teFont
  701.     Move.b            TempFace+1(A4),teFace(A0)    ; teFace
  702.     Move.w        TempSize(A4),teSize(A0)        ; teSize
  703.     Move.w        info+ascent(A4),teAscent(A0)    ; teAscent
  704.     Move.w        info+ascent(A4),D0            ; teLineHite
  705.     Add.w            info+descent(A4),D0
  706.     Add.w            info+leading(A4),D0
  707.     Move.w        D0,teLineHite(A0)
  708.     Move.l            teViewRect+topLeft(A0),teDestRect+topLeft(A0)
  709.     Move.l            teViewRect+botRight(A0),teDestRect+botRight(A0)
  710.     Mulu            teNLines(A0) ,D0        ; Height of the sample text.
  711.     Move.w        SampleRect+bottom(A4),D1
  712.     Sub.w            SampleRect+top(A4),D1
  713.     Cmp.w            D0,D1                    ; Sample greater than Rect?
  714.     Ble                @0                        ; Yes -> @0
  715.     Sub.w            D0,D1                    ; Center the sample
  716.     Lsr.w            #1,D1                    ; lines in the middle
  717.     Add.w            D1,teDestRect+top(A0)    ; of SampleRect.
  718. @0    Rts
  719.  
  720.  
  721. ; --------------------- Modal Dialog User Filter ---------------------------    
  722. DUserFilter
  723.  
  724.     Link            A6,#0
  725.     ; Boolean result                            20(A6)
  726.     ; Dialog (window) pointer                    16(A6)
  727.     ; Address of the event record                12(A6)
  728.     ; Address of word to fill in with item number     8(A6)
  729.     ; Return address                             4(A6)
  730.     ; Old A6                                      (A6)
  731.     
  732. ; Use the event number as an index into the DEventTable.  These 12 events are
  733. ; all the things that could spontaneously happen while the program is in
  734. ; the Modal Dialog event loop.
  735.     
  736.     Movea.l        16(A6),A4                ; Font Dialog Data Record.
  737.  
  738.     Move.w        #False,20(A6)            ; Set the function result to False.
  739.     Movea.l        12(A6),A0                ; Event Records Address.
  740.     Move.w        evtNum(A0),D0            ; Get the event number.
  741.     Lsl.w            #1,D0                    ; *2 for table index.
  742.     Move.w        DEventTable(D0.W),D0    ; Point to the routine offset
  743.     Jmp            DEventTable(D0.W)    ; and jump to it.
  744.     
  745. DEventTable
  746.     Dc.w    DNull-DEventTable                ; Null    
  747.     Dc.w    DMouseDown-DEventTable        ; Mouse Down
  748.     Dc.w    DFReturn-DEventTable            ; Mouse Up     (Not used)
  749.     Dc.w    DKeyDown-DEventTable        ; Key Down
  750.     Dc.w    DFReturn-DEventTable            ; Key Up         (Not used)
  751.     Dc.w    DKeyDown-DEventTable        ; Auto Key
  752.     Dc.w    DUpdate-DEventTable            ; Update     
  753.     Dc.w    DFReturn-DEventTable            ; Disk             (Not used)
  754.     Dc.w    DActivate-DEventTable        ; Activate    
  755.     Dc.w    DFReturn-DEventTable            ; Network         (Not used)
  756.     Dc.w    DFReturn-DEventTable            ; I/O Driver        (Not used)
  757.  
  758. DNull
  759.     GetDItem         16(A6),#20,Itemtype(A4),Item(A4),ItemBox(A4)
  760.     GetMouse        loc_pt(A4)
  761.     PtInRect         loc_pt(A4),ItemBox(A4)    ; Was the mouse within the 
  762.     Move.b            (SP)+,D0                ; FontSize text edit Rect?
  763.     Beq.s            @0                        ; Yes -> iBeam cursor.
  764.     ; Procedure SetCursor (crsr: Cursor)
  765.     Move.l            TextCursor(A4),A0    
  766.     Move.l            (A0),-(SP)
  767.     _SetCursor
  768.     Bra                @1
  769. @0    _InitCursor                                ; No -> Arrow cursor.
  770.  
  771. @1    Move.l            Ticks,D0                ; If KeyTresh Ticks have passed
  772.     Sub.l            SampleTicks(A4),D0    ; since the last item alteration,
  773.     Cmp.w            KeyThresh,D0            ; update the sample window by
  774.     Blt                DFReturn                ; indicating item #21 was hit.
  775.     Btst.b            #SUpdate,DFlags(A4)
  776.     Beq            DFReturn
  777.     
  778.     Move.w        #21,D0                    ; Set the itemNo to 21, Sample
  779.     Bra                DFTReturn
  780.  
  781.  
  782. DMouseDown
  783.     Bclr.b            #SKey,DFlags(A4)        ; Not a SKey event.
  784.     ; Obtain the (events) mouse location and convert it to local coordinates.
  785.     Move.l            evtMouse(A0),loc_pt(A4)
  786.     GlobalToLocal    loc_pt(A4)
  787.     
  788. ; Check to see if the mouse was clicked inside one of the active rectangles.    
  789.  
  790. Item9
  791. ;- Check to see if the mouse was pressed down within item No 9 (Style heading) 
  792.     GetDItem         FontDPtr,#9,Itemtype(A4),Item(A4),ItemBox(A4)
  793.     PtInRect         loc_pt(A4),ItemBox(A4)
  794.     Move.b            (SP)+,D0                ; Was the point within the heading?
  795.     Beq.s            Item14                    ; No -> check item No 14's Rect.
  796.  
  797.     ; Routine TrackHeading (theDialog: DialogPtr; itemNo: Integer): Boolean
  798.     Subq.l            #2,SP                    ; Set up for the result.
  799.     Move.l            FontDPtr,-(SP)
  800.     Move.w        #9,-(SP)
  801.     Bsr                TrackHeading
  802.     Move.b            (SP)+,D0                ; Was the mouse up within the item?
  803.     Beq            SetoNull                ; No, Convert the event to null & return    .
  804.     Move.w        #9,D0                    ; Yes, return True & the item No 9.
  805.     Bra                DFTReturn
  806.     
  807. Item14
  808. ;- Check to see if the mouse was pressed down within item No 14 (Spacing heading).
  809.     GetDItem         FontDPtr,#14,Itemtype(A4),Item(A4),ItemBox(A4)
  810.     PtInRect         loc_pt(A4),ItemBox(A4)
  811.     Move.b            (SP)+,D0                ; Was the point within the heading?
  812.     Beq            Item17                    ; No -> check item No 17's Rect.
  813.  
  814.     ; Routine TrackHeading (theDialog: DialogPtr; itemNo: Integer): Boolean;
  815.     Subq.l            #2,SP
  816.     Move.l            FontDPtr,-(SP)
  817.     Move.w        #14,-(SP)
  818.     Bsr                TrackHeading
  819.     Move.b            (SP)+,D0                ; Was the mouse up within the item?
  820.     Beq            SetoNull                ; No, Convert the event to null & return    .
  821.     Move.w        #14,D0                    ; Yes, return True & the item No 14.
  822.     Bra                DFTReturn
  823.  
  824. Item17
  825. ; Check to see if the mouse was pressed down within item No 17
  826. ; The Font Name Selection Window.
  827.     GetDItem         FontDPtr,#17,Itemtype(A4),Item(A4),ItemBox(A4)
  828.     Addi.w            #15,ItemBox+right(A4)        ; include the vertical scroll bar.
  829.     PtInRect         loc_pt(A4),ItemBox(A4)
  830.     Move.b            (SP)+,D0                    ; Was the point within the rect?
  831.     Beq            Item19                        ; No -> check item No 19's rect.
  832.     
  833. ; If a new selection is made return true and the item number, otherwise
  834. ; set the event to a null event and return.
  835.     ; Function LClick (pt: Point; modifiers: Integer; lHandle: ListHandle): Boolean
  836.     Subq.l            #2,SP
  837.     Move.l            loc_pt(A4),-(SP)
  838.     Movea.l        12(A6),A0
  839.     Move.w        evtMeta(A0),-(SP)
  840.     Move.l            NameListH(A4),-(SP)
  841.     _LClick
  842.     Addq.l            #2,SP
  843.     
  844.     Clr.l            TempCell(A4)
  845.     LMGetSelect     #True,TempCell(A4),NameListH(A4)
  846.     Move.b            (SP)+,D0                    ; Is there a selected cell?
  847.     Bne            @0                            ; Yes -> @0.
  848.     Move.l            #$FFFF0000,TempCell(A4)    ; No set TempCell to 0,-1.
  849. @0    Move.l            TempCell(A4),D0            ; Has the selected cell changed?
  850.     Cmp.l            NameCell(A4),D0
  851.     Beq            SetoNull                    ; No -> SetoNull.
  852.     Move.l            D0,NameCell(A4)            ; Yes, return True & the item No 17.
  853.     Move.w        #17,D0
  854.     Bra                DFTReturn
  855.     
  856.     
  857. Item19
  858. ; Check to see if the mouse was pressed down within item No 19. 
  859. ; The Font Size Selection Window.
  860.     GetDItem         FontDPtr,#19,Itemtype(A4),Item(A4),ItemBox(A4)
  861.     Addi.w            #15,ItemBox+right(A4)        ; Include the vertical scroll bar.
  862.     PtInRect         loc_pt(A4),ItemBox(A4)
  863.     Move.b            (SP)+,D0                    ; Was the point within the rect?
  864.     Beq            DFReturn                    ; No -> DFReturn.
  865.     
  866. ; If a new selection is made return true and the item number, otherwise
  867. ; set the event to a null event and return.
  868.     ; Function LClick (pt: Point; modifiers: Integer; lHandle: ListHandle): Boolean
  869.     Subq.l            #2,SP
  870.     Move.l            loc_pt(A4),-(SP)
  871.     Movea.l        12(A6),A0
  872.     Move.w        evtMeta(A0),-(SP)
  873.     Move.l            SizeListH(A4),-(SP)
  874.     _LClick
  875.     Addq.l            #2,SP
  876.     
  877.     Clr.l            TempCell(A4)
  878.     LMGetSelect     #True,TempCell(A4),SizeListH(A4)
  879.     Move.b            (SP)+,D0                ; Is there a selected cell?
  880.     Bne            @0                        ; Yes -> @0.
  881.     Move.l            #$FFFF0000,TempCell(A4)
  882. @0    Move.l            TempCell(A4),D0        ; Has the selected cell changed?
  883.     Cmp.l            SizeCell(A4),D0
  884.     Beq            SetoNull                ; No -> SetoNull.
  885.     Move.l            D0,SizeCell(A4)        ; Yes, return True & the item No 19.
  886.     Move.w        #19,D0
  887.     Bra                DFTReturn
  888.  
  889.  
  890. DKeyDown
  891.     ; Examine the key that was pressed, if it was a 'cr' or 'enter' then that is
  892.     ; equivalent to clicking the Ok button.
  893.     Move.l            evtMessage(A0),D0    
  894.     Cmpi.b            #crCode,D0            ; Was the cr key pressed?
  895.     Beq.s            @1                        ; Yes -> @1.
  896.     Cmpi.b            #enterCode,D0            ; Was the enter key pressed?
  897.     Bne.s            @2                        ; No -> @2.
  898. @1    Move.w        #1,D0                    ; Set the item No to the Ok button.
  899.     Bra                DFTReturn                ; Item No 1 - Ok.
  900.  
  901. @2    ; If the key pressed was the back space key or a number then deselect 
  902.     ; the cell in the Font Size Selection Window (if there is one selected),
  903.     ; then return, allowing the number or 'bs' to be used to alter the FontSize
  904.     ; text edit data.
  905.     Cmpi.b            #bsCode,D0            ; Was the bs key pressed?
  906.     Beq.s            @3                        ; Yes -> @3.
  907.     Cmpi.b            #$30,D0
  908.     Blt.s            NameSearch
  909.     Cmpi.b            #$39,D0
  910.     Bgt.s            NameSearch
  911. @3    Bclr.b            #SKey,DFlags(A4)        ; Not a SKey event.
  912.     Cmpi.l            #$FFFF0000,SizeCell(A4)            ; If a cell is selected,
  913.     Beq            DFReturn                            ; deselect it, then let 
  914.     LMSetSelect     #False,SizeCell(A4),SizeListH(A4)    ; the default routine 
  915.     Move.l            #$FFFF0000,SizeCell(A4)            ; handle the event.
  916.     Bra                DFReturn
  917.  
  918. NameSearch
  919.     Lea            search(A4),A2
  920.     Bset.b            #SKey,DFlags(A4)        ; Was the last event a SKey event?
  921.     Beq.s            @0                        ; No -> @0
  922.     Move.l            evtTicks(A0),D1        ; Yes -> If this key down occured
  923.     Sub.l            SampleTicks(A4),D1    ;    within KeyThresh Ticks of the last
  924.     Cmp.w            KeyThresh,D1            ;    continue the search string
  925.     Blt.s            @1                        ;    else, reset the search string.
  926. @0    Clr.b            (A2)                    ; Continue.
  927. @1    Addq.b            #1,(A2)                    ; Reset.
  928.     Move.l            evtTicks(A0),SampleTicks(A4)    
  929.     Clr.w            D1                        ; If search string is greater than
  930.     Move.b            (A2),D1                ; 32, SetoNull.
  931.     Cmpi.b            #31,D1
  932.     Bgt                SetoNull
  933.     Move.b            D0,(A2,D1.w)            ; Add char to string.
  934.     
  935.     DeRefHndle    FontMap(A5),A3
  936.     Clr.w            D7                        ; Set loop counter.
  937. @2    Move.w        D7,D6
  938.     Mulu            #6,D6                    ; Offset to next font info.
  939.     Move.w        2+2(A3,D6.w),D6        ; Offset to name string.
  940.     ; Function IUMagString (aPtr, bPtr: Ptr; aLen, bLen: Integer): Integer
  941.     Subq.l            #2,SP
  942.     Pea            1(A3,D6.w)                ; Address of FontName string.
  943.     Pea            1(A2)                    ; Address of search string.
  944.     Clr.w            D0
  945.     Move.b            (A3,D6.w),D0
  946.     Move.w        D0,-(SP)                ; Length of FontName string.
  947.     Move.b            (A2),D0
  948.     Move.w        D0,-(SP)                ; Length of search string.
  949.     _IUMagString
  950.     Move.w        (SP)+,D0                ; Was the FontName => ?
  951.     Bpl.s            @3                        ; Yes -> @3
  952.     
  953.     Addq.w            #1,D7                    ; Have all the fonts been 
  954.     Cmp.w            (A3),D7                ; looked at?
  955.     Blt                @2                        ; No -> @2
  956.     
  957. @3        ; Is the desired cell selected?
  958.         ; Yes -> Don't do anything.
  959.         ; No -> Deselect the existing cell & select the new cell.
  960.     Cmp.w            NameCell+v(A4),D7
  961.     Beq            SetoNull
  962.     LMSetSelect    #False,NameCell(A4),NameListH(A4)
  963.     Move.w        D7,NameCell+v(A4)
  964.     LMSetSelect    #True,NameCell(A4),NameListH(A4)
  965.     
  966.     DeRefHndle    NameListH(A4),A0        ; If the selected cell isn't visible
  967.     Cmp.w            visible+top(A0),D7        ; then     AutoScroll.
  968.     Blt.s            @4                        ; else     continue.
  969.     Cmp.w            visible+bottom(A0),D7
  970.     Blt.s            @5
  971. @4    LMAutoScroll    NameListH(A4)
  972. @5    Move.w        #17,D0
  973.     Bra                DFTReturn
  974.  
  975.  
  976. DUpdate
  977.     Bclr.b            #SKey,DFlags(A4)        ; Not a SKey event.
  978.     SetPort        FontDPtr
  979.     BeginUpdate    FontDPtr
  980.     DrawControls    FontDPtr
  981.  
  982. ;-*- Update itemNo 1 -------------------------------------------------------    
  983.     ; The BoldBox around the Ok button.
  984.     GetDItem        FontDPtr,#1,Itemtype(A4),Item(A4),ItemBox(A4)
  985.     InsetRect        ItemBox(A4),#-4,#-4
  986.     PenSize        #3,#3
  987.     FrameRoundRect    ItemBox(A4),#16,#16
  988.     _PenNormal
  989.     
  990. ;-*- Update itemNo 3 -------------------------------------------------------
  991.     ; The Static Text heading "Character Font & Attributes".
  992.     GetDItem        FontDPtr,#3,Itemtype(A4),Item(A4),ItemBox(A4)
  993.     GetIText         Item(A4),thename(A4)
  994.     Lea            thename(A4),A0        ; Address of the text.
  995.     Clr.l            D0
  996.     Move.b            (A0)+,D0                ; Length of the text.
  997.     TextBox         A0,D0,ItemBox(A4),#0
  998.     
  999. ;-*- Update the Font Style Selection Window --------------------------------
  1000.     ; The ThinBox around the Style Check Boxes         (item No 10).
  1001.     GetDItem         FontDPtr,#10,Itemtype(A4),Item(A4),ItemBox(A4)
  1002.     FrameRect        ItemBox(A4)
  1003.  
  1004.     ; The Static Text heading "Style"                     (item No 9).    
  1005.     GetDItem         FontDPtr,#9,Itemtype(A4),Item(A4),ItemBox(A4)
  1006.     GetIText         Item(A4),thename(A4)
  1007.     Lea            thename(A4),A0        ; Address of the text.
  1008.     Clr.l            D0
  1009.     Move.b            (A0)+,D0                ; Length of the text.
  1010.     TextBox         A0,D0,ItemBox(A4),#0
  1011.     
  1012. ;-*- Update the Font Spacing Selection Window --------------------------------
  1013.     ; The ThinBox around the Style Check Boxes         (item No 15).
  1014.     GetDItem         FontDPtr,#15,Itemtype(A4),Item(A4),ItemBox(A4)
  1015.     FrameRect        ItemBox(A4)
  1016.  
  1017.     ; The static text heading "Spacing"                     (item No 14).    
  1018.     GetDItem         FontDPtr,#14,Itemtype(A4),Item(A4),ItemBox(A4)
  1019.     GetIText         Item(A4),thename(A4)
  1020.     Lea            thename(A4),A0        ; Address of the text.
  1021.     Clr.l            D0
  1022.     Move.b            (A0)+,D0                ; Length of the text.
  1023.     TextBox         A0,D0,ItemBox(A4),#0
  1024.     
  1025. ;-*- Update itemNo 16 ------------------------------------------------------
  1026.     ; The Static Text heading "Font Name:".
  1027.     GetDItem         FontDPtr,#16,Itemtype(A4),Item(A4),ItemBox(A4)
  1028.     GetIText         Item(A4),thename(A4)
  1029.     Lea            thename(A4),A0        ; Address of the text.
  1030.     Clr.l            D0
  1031.     Move.b            (A0)+,D0                ; Length of the text.
  1032.     TextBox         A0,D0,ItemBox(A4),#0
  1033.  
  1034. ;-*- Update itemNo 17 ------------------------------------------------------
  1035.     ; The Font Name Selection Window.
  1036.     GetDItem         FontDPtr,#17,Itemtype(A4),Item(A4),ItemBox(A4)
  1037.     InsetRect         ItemBox(A4),#-1,#-1
  1038.     EraseRect         ItemBox(A4)
  1039.     FrameRect         ItemBox(A4)
  1040.     LMUpdate         VisRgn(A4),NameListH(A4)
  1041.     
  1042. ;-*- Update itemNo 18 ------------------------------------------------------
  1043.     ; The Static Text heading "Font Size:".
  1044.     GetDItem         FontDPtr,#18,Itemtype(A4),Item(A4),ItemBox(A4)
  1045.     GetIText         Item(A4),thename(A4)
  1046.     Lea            thename(A4),A0        ; Address of the text.
  1047.     Clr.l            D0
  1048.     Move.b            (A0)+,D0                ; Length of the text.
  1049.     TextBox         A0,D0,ItemBox(A4),#0
  1050.     
  1051. ;-*- Update itemNo 19 ------------------------------------------------------
  1052.     ; The Font Size Selection Window.
  1053.     GetDItem         FontDPtr,#19,Itemtype(A4),Item(A4),ItemBox(A4)
  1054.     InsetRect         ItemBox(A4),#-1,#-1
  1055.     EraseRect         ItemBox(A4)
  1056.     FrameRect         ItemBox(A4)
  1057.     LMUpdate         VisRgn(A4),SizeListH(A4)
  1058.     
  1059. ;-*- Update itemNo 20 ------------------------------------------------------
  1060.     ; The TextEdit text item.
  1061.     GetDItem         FontDPtr,#20,Itemtype(A4),Item(A4),ItemBox(A4)
  1062.     EraseRect         ItemBox(A4)
  1063.     TEUpdate         ItemBox(A4),teHandle(A4)
  1064.     InsetRect         ItemBox(A4),#-3,#-3
  1065.     FrameRect         ItemBox(A4)            ; Frame the textedit item.
  1066.  
  1067. ;-*- Update itemNo 21 ------------------------------------------------------
  1068.     ; Update the Sample Text Window.
  1069.     EraseRect         SampleRect(A4)
  1070.     Bclr.b            #SRect,DFlags(A4)
  1071.     Btst.b            #OkActive,DFlags(A4)            ; Are the selections valid?
  1072.     Beq            @0                                ; No -> @0
  1073.     TEUpdate         SampleRect(A4),Sample(A4)    ; Yes -> update the sample
  1074.     Move.l            Ticks,SampleTicks(A4)            ;    and associated
  1075.     Bclr.b            #SUpdate,DFlags(A4)            ;     variables.
  1076.     Bset.b            #SRect,DFlags(A4)
  1077.  
  1078. @0    EndUpdate        FontDPtr
  1079.     Bra                SetoNull
  1080.     
  1081.     
  1082. DActivate
  1083. ; Check first to see if this activate event is associated with this Dialog
  1084. ; Window, compare the Dialog Window's pointer to that of the Window pointer
  1085. ; in the event record. A0 contains the address of the event record.
  1086.     Move.l            FontDPtr,D0
  1087.     Cmp.l            evtMessage(A0),D0
  1088.     Bne            DFReturn                ; Event not related to Dialog.
  1089.         
  1090.     Bclr.b            #SKey,DFlags(A4)        ; Not a SKey event.
  1091.     SetPort        FontDPtr
  1092.     Movea.l        12(A6),A0                ; Address of the event record.
  1093.     Move.w        evtMeta(A0),D0        ; Obtain the modify word.
  1094.     Lsr                #1,D0                    ; Check Bit 0 to see if its
  1095.     Bcc            DDeactivate            ; Activate or Deactivate.
  1096.     
  1097.     TEActivate        teHandle(A4)
  1098.     LMActivate     #True,NameListH(A4)
  1099.     LMActivate     #True,SizeListH(A4)
  1100.     Bra                SetoNull
  1101.  
  1102. DDeactivate
  1103.     TEDeactivate    teHandle(A4)
  1104.     LMActivate     #False,NameListH(A4)
  1105.     LMActivate     #False,SizeListH(A4)
  1106.     Bra                SetoNull
  1107.     
  1108.  
  1109. SetoNull
  1110.     Movea.l        12(A6),A0                ; Obtain the address of the Event
  1111.     Clr.w            evtNum(A0)            ; Record & set it to a null event.
  1112.     Bra.s            DFReturn
  1113. DFTReturn
  1114.     Move.b            #True,20(A6)            ; Dialog Filter (True) Return.
  1115.     Movea.l        8(A6),A0
  1116.     Move.w        D0,(A0)
  1117. DFReturn                                    ; Dialog Filter Return.
  1118.     Unlk            A6
  1119.     Movea.l        (SP)+,A0                ; Pop args & return.
  1120.     Add.l            #12,SP
  1121.     Jmp            (A0)
  1122.  
  1123.     
  1124. TrackHeading
  1125.     Link            A6,#-22
  1126.     ; Boolean result                         14(A6)
  1127.     ; theDialog pointer                         10(A6)
  1128.     ; itemNo                                  8(A6)
  1129.     ; Return address                          4(A6)
  1130.     ; Old A6                                   (A6)
  1131.     ; Temporary Region Handle No1             -4(A6)
  1132.     ; Temporary Region Handle No2            -8(A6)
  1133.     ; Vis boolean                            -10(A6)
  1134.     ; Mouse Location                        -14(A6)
  1135.     ; Temporary Rectangle                    -22(A6)
  1136.     
  1137.     Move.b            #False,14(A6)            ; Set up to return False.
  1138.     
  1139. ;- Get the Rect of the user item that surrounds the headings control items
  1140. ;  (check boxes or radio buttons).
  1141.     Addq.w            #1,8(A6)
  1142.     GetDItem         10(A6),8(A6),Itemtype(A4),Item(A4),-22(A6)
  1143.     
  1144. ;- Create a region and store in it the current clipping region.    
  1145.     NewRgn
  1146.     Move.l            (SP),-4(A6)                ; Store the regions handle.
  1147.     _GetClip
  1148.  
  1149. ;- Create a new clipping region which is the user item's rect inset by 1 pixel
  1150. ;  on all sides minus the intersection rectangle of the heading's rect
  1151. ;  and the newly created rect.
  1152.     NewRgn
  1153.     Move.l            (SP),-8(A6)                ; Store the regions handle.
  1154.     InsetRect         -22(A6),#1,#1
  1155.     _OpenRgn
  1156.     FrameRect        -22(A6)        
  1157.     
  1158. ;- Find the rectangle that is the intersection of ItemBox(A4) and -22(A6). 
  1159. ;  If they intersect then remove that rectangle from the clipping region.
  1160.     SectRect         ItemBox(A4),-22(A6),TempRect
  1161.     Move.b            (SP)+,D0                ; Was there an intersection?
  1162.     Beq.s            @1                        ; No -> @1.
  1163.     FrameRect        TempRect
  1164. @1    _CloseRgn                                ; The handle is already on the stack.
  1165.     SetClip            -8(A6)                    ; Set up the new clipping region.
  1166.  
  1167.     PenSize         #1,#1
  1168.     PenMode        #10                    ; Inverts what ever is drawn over.
  1169.     
  1170. ; Draw the rectangle in question, giving the user the impression that they
  1171. ; have selected the heading.
  1172.     FrameRect        -22(A6)
  1173.     Move.b            #True,-10(A6)            ; Set the vis byte to True.
  1174.     
  1175. Track    
  1176.     StillDown
  1177.     Move.b            (SP)+,D0                ; Is the mouse button still down?
  1178.     Beq            @1                        ; No -> @1.
  1179.     GetMouse        -14(A6)
  1180.     PtInRect         -14(A6),ItemBox(A4)
  1181.     Move.b            (SP)+,D0                ; Has the mouse entered or
  1182.     Cmp.b            -10(A6),D0                ; left the item's rect?
  1183.     Beq.s            Track                    ; No -> Track.
  1184.     FrameRect        -22(A6)                    ; Yes -> toggle the rectangle.
  1185.     Eori.b            #1,-10(A6)                ; Toggle the visible byte.
  1186.     Bra.s            Track
  1187.     
  1188. @1    Move.b            -10(A6),D0                ; Is the rect visible?
  1189.     Beq.s            @2                        ; No -> Return False.
  1190.     FrameRect        -22(A6)                    ; Yes -> Remove the rectangle &    
  1191.     Move.b            #True,14(A6)            ;       return True.
  1192. @2    _PenNormal    
  1193.     SetClip            -4(A6)                    ; Reset to its original setting.
  1194.     DisposeRgn     -4(A6)                    ; Dispose of the two temporary regions.
  1195.     DisposeRgn     -8(A6)
  1196.     
  1197.     Unlk             A6
  1198.     Movea.l        (SP)+,A0                ; Pop args & return.
  1199.     Add.l            #6,SP
  1200.     Jmp            (A0)
  1201.     
  1202.     
  1203. ; ---------- Variables ------    
  1204.  
  1205. FontDRec            Ds.l        1